#!/bin/bash                                                                                                

#SBATCH -c 8
#SBATCH -N 1
#SBATCH -t 6-23:59:00
#SBATCH -p huce_intel
#SBATCH --constraint=intel
#SBATCH --mem=2500
#SBATCH --mail-type=ALL
#SBATCH --no-requeue
#SBATCH --mail-user=kelvin_bates@g.harvard.edu
#SBATCH -o stdout.%j
#SBATCH -e stdout.%j

ctr=0
#sed -i "s/RTOL(i) = 1.0d-4/RTOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90
#sed -i "s/ATOL(i) = 1.0d-3/ATOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90

for valAROMmag in 8 7 6 5 4
do
    for valAROM in 1 2 5
    do
        sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2401E-8)#($valAROM.0E-$valAROMmag*1.2401E-8)#g" aromatics_kpp_Rates.f90
        sed -i "s#(..0E-.*1.2023E-8)#($valAROM.0E-$valAROMmag*1.2023E-8)#g" aromatics_kpp_Rates.f90
        sed -i "s#(..0E-.*6.6138E-9)#($valAROM.0E-$valAROMmag*6.6138E-9)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new3_ambient_$ctr.dat
            done
        done
    done
done
sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2023E-8)#(0.0E-9*1.2023E-8)#g" aromatics_kpp_Rates.f90
sed -i "s#(..0E-.*6.6138E-9#(0.0E-9*6.6138E-9#g" aromatics_kpp_Rates.f90
for valAROMmag in 8 7 6 5 4
do
    for valAROM in 1 2 5
    do
        sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2401E-8)#($valAROM.0E-$valAROMmag*1.2401E-8)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new3_ambient_$ctr.dat
            done
        done
    done
done
sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2401E-8)#(0.0E-9*1.2401E-8)#g" aromatics_kpp_Rates.f90
for valAROMmag in 8 7 6 5 4
do
    for valAROM in 1 2 5
    do
        sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2023E-8)#($valAROM.0E-$valAROMmag*1.2023E-8)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new3_ambient_$ctr.dat
            done
        done
    done
done
sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2023E-8)#(0.0E-9*1.2023E-8)#g" aromatics_kpp_Rates.f90
for valAROMmag in 8 7 6 5 4
do
    for valAROM in 1 2 5
    do
        sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*6.6138E-9#($valAROM.0E-$valAROMmag*6.6138E-9#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new3_ambient_$ctr.dat
            done
        done
    done
done

sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new3_ambient_*.dat

# Exit normally
exit 0
#EOC
